<?php
 header("Content-Type:text/html;charset=utf-8");//防止网页中文乱码
// //接受提交的数据
//echo $_REQUEST['username'];
//echo "<br/>";
//echo $_REQUEST['message'];
//echo "<br/>";
//echo $_REQUEST['sex'];
//echo "<br/>";
//echo $_REQUEST['imgurl'];
 //往数据表里添加一条留言
 //(1)连接数据库
 require 'dbcon.php';
 $username=$_REQUEST['username'];//获取用户呢称
 $sex=$_REQUEST['sex'];
 $message=$_REQUEST['message'];
 $imgurl=$_REQUEST['imgurl'];// 获取用户留言
 date_default_timezone_set('Asia/Shanghai');//设置时区
 $m_date=date("Y-m-d h:i:s");  //获取当前的日期时间
 $sql="insert into t_message(username,sex,message,imgurl,m_date) values('{$username}', '{$sex}','{$message}','{$imgurl}','{$m_date}')";//写SQL语句
 $rs=$db->query($sql);//执行SQL语句
 if  ($rs==true)
 {
    echo "<script language='javascript' type='text/javascript'>"; 
    //echo "alert('留言成功！');";
    echo "window.location.href='index.php';";
    echo "</script>";
 }
 else {
    echo "<script language='javascript' type='text/javascript'>"; 
    echo "alert('留言失败！');";
    echo "window.location.href='index.php';";
    echo "</script>";
}

$db->close();